package com.fivefu.core.gb28181.config;

import com.fivefu.core.gb28181.listner.SipServerLayer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import java.util.TooManyListenersException;

@Configuration
public class SipLayerConfig {

    @Value("${ffgb.config.listenIp}")
    String listenIp;

    @Value("${ffgb.config.listenPort}")
    Integer listenPort;

    @Bean
    public SipServerLayer sipServerLayer(){
        SipServerLayer sipServerLayer = null;
        try {
            sipServerLayer = new SipServerLayer(listenIp,listenPort);
            System.out.println("SIP监听启动,IP:" + listenIp + ",Port:" + listenPort);
        } catch (SipException e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        } catch (InvalidArgumentException e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        } catch (TooManyListenersException e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
        return sipServerLayer;
    }

}
